﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;
using System.Data;
using System.Net;

namespace Dryricenet.houTai
{
    public partial class user_Delete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = Session["UserName"].ToString();
            System.Data.DataTable dt = userBLL.selectNameBll(name);
            DataRow dr = dt.Rows[0];//第一条数据
            int userID = Convert.ToInt32(dr["UserID"].ToString());
            int id = Convert.ToInt32(Request.QueryString["UserID"]);
            int glid = Convert.ToInt32(userBLL.idGLBLL(id));
            Log l = new Log();
            l.OperTime = DateTime.Now;
            l.OperPerson = name;
           

            if (glid == 2)
            {
                if (userID == 1)
                {
                    l.Type = "删除管理员";
                    l.State = "删除成功";
                    l.ComputerName = Dns.GetHostName().ToUpperInvariant();
                    l.System = Systems.GetOSNameByUserAgent(Environment.OSVersion.ToString());
                    l.UserID = userID;
                    LogBLL.LogAddBLL(l);
                    userBLL.deleteBll(id);
                    Response.Redirect("userSelect.aspx");
                }
                else
                {
                    Response.Write("<script>alert('您不是超级管理员无法删除管理员！')</script>");

                }
            }
            else
            {
                l.Type = "删除用户";
                l.State = "删除成功";
                l.ComputerName = Dns.GetHostName().ToUpperInvariant();
                l.System = Systems.GetOSNameByUserAgent(Environment.OSVersion.ToString());
                l.UserID = userID;
                LogBLL.LogAddBLL(l);
                userBLL.deleteBll(id);
                Response.Redirect("userSelect.aspx");
            }

        }
    }
}